﻿using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Organ.API.Application.Commands.DepartmentCommands;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FarmSmartSleep.Organ.API.Controllers
{
    /// <summary>
    /// 部门控制器--API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartController : ControllerBase
    {
        private readonly IMediator mediator;

        public DepartController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddDepart(DepartmentCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 部门级联添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddDepartTree(DepartmentTreeCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 部门级联显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchDepartmentTree()
        {
            return await mediator.Send(new DepartTreeSearchCommand());
        }
        /// <summary>
        /// 部门类型显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchDepartType()
        {
            return await mediator.Send(new DepartTypeSearchCommands());
        }
        /// <summary>
        /// 职能部门显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchFunction()
        {
            return await mediator.Send(new FunctionalSystemSearchCommand());
        }
        /// <summary>
        /// 部门显示
        /// </summary>
        /// <param name="DepartmentName"></param>
        /// <param name="DepartmentTypeId"></param>
        /// <param name="Pindex"></param>
        /// <param name="Psize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultPage<DepartTypeDtos>> GetDepartment (string? DepartmentName, int DepartmentTypeId, int Pindex, int Psize)
        {
            return await mediator.Send(new DepartSearchCommand { DepartmentName = DepartmentName, DepartmentTypeId = DepartmentTypeId, Pindex = Pindex, Psize = Psize });
        }

    }
}
